package com.lc.rongzecaifu.fragment;


import android.content.Intent;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.RadioButton;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.lc.rongzecaifu.MyApplication;
import com.lc.rongzecaifu.activity.IoanActivity;
import com.lc.rongzecaifu.activity.MainActivity;
import com.lc.rongzecaifu.adapter.AnswerQuestionAdapter;
import com.lc.rongzecaifu.conn.JsonAccessToken;
import com.lc.rongzecaifu.conn.JsonBorrowindex;
import com.lc.rongzecaifu.rongzecaifu.R;
import com.lc.rongzecaifu.toast.LovelyToast;
import com.lc.rongzecaifu.view.BorrowPop;
import com.zcx.helper.activity.AppV4Fragment;
import com.zcx.helper.bound.BoundViewHelper;
import com.zcx.helper.http.AsyCallBack;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

import static com.lc.rongzecaifu.rongzecaifu.R.id.all_limit;
import static com.lc.rongzecaifu.rongzecaifu.R.id.borrow_type;
import static com.lc.rongzecaifu.rongzecaifu.R.id.daylimit;
import static com.lc.rongzecaifu.rongzecaifu.R.id.nolimit;
import static com.lc.rongzecaifu.rongzecaifu.R.id.tender_award_nosel_rb;


/**
 * A simple {@link Fragment} subclass.
 */
public class FourthFragment2 extends AppV4Fragment implements View.OnClickListener {




    @Bind(R.id.bt_next)
    Button btNext;




    private PopupWindow popLeft;
    private View layoutLeft;


    private ListView menulistLeft;
    private List<JsonBorrowindex.Info.ListContent> borrow_use = new ArrayList<>();
    private List<String> stringListBorrow_use = new ArrayList<>();

    private List<JsonBorrowindex.Info.ListContent> borrow_use_day = new ArrayList<>();


    private List<String> stringListBorrow_use_day = new ArrayList<>();


    private List<JsonBorrowindex.Info.ListContent> borrow_money = new ArrayList<>();
    private List<String> myborrow_money = new ArrayList<>();


    private List<JsonBorrowindex.Info.ListContent> sex = new ArrayList<>();
    private List<String> mysex = new ArrayList<>();

    private List<JsonBorrowindex.Info.ListContent> borrow_duration_month = new ArrayList<>();
    private List<String> myborrow_duration = new ArrayList<>();


    private List<JsonBorrowindex.Info.ListContent> retypement = new ArrayList<>();
    private List<String> str_retypement = new ArrayList<>();


    //还款方式id
    private String type_repyment;


    //借款用途id
    private String borrow_use_id;

    //奖励类型

    private List<JsonBorrowindex.Info.ListContent> reward_type = new ArrayList<>();

    //奖励类型id
    private String reward_type_id;
    private List<String> reward_type_list = new ArrayList<>();


//最高投资金额

    private String zuigao_id;
    //最低投资金额
    private List<JsonBorrowindex.Info.ListContent> borrow_min = new ArrayList<>();
    private String borrow_min_id;
    private List<String> borrow_min_list = new ArrayList<>();
    //有效时间
    private List<JsonBorrowindex.Info.ListContent> borrow_time = new ArrayList<>();
    private String borrow_time_id;
    private List<String> borrow_time_list = new ArrayList<>();

//贷款期限的id

    public String qixianid;

    //贷款期限的id
    private String daikuanqixian;


    public static boolean type_daikuan = false;
    //借款总额
    String str_allmoney;
    //借款总额的判断
    Double d;
    int a;

    String jinebili;

    Double double_pay;
    int int_pay;

    //最高投资
    private List<JsonBorrowindex.Info.ListContent> borrow_max = new ArrayList<>();
    private List<String> stringListBorrow_max = new ArrayList<>();

    //待收限制
    private List<JsonBorrowindex.Info.ListContent> daishou = new ArrayList<>();
    private List<String> daishou_str = new ArrayList<>();
    private String daishou_id = "0";

    List<String> data = new ArrayList<String>();







    //最高投资金额
    @Bind(R.id.maxborrow_layout)
    LinearLayout maxborrow_layout;
    //最高投资金额TextVIew
    @Bind(R.id.et_maxinvest)
    TextView et_maxinvest;

    String et_moneymax;
    String et_moneymax2;


    //最低投资金额
    @Bind(R.id.minborrow_layout)
    LinearLayout minborrow_layout;
    @Bind(R.id.et_mininvest)
    TextView et_mininvest;





    //是否投标奖励
    @Bind(R.id.linearlayout_bili)
    LinearLayout linearlayout_bili;
    //投标比例
    @Bind(R.id.check_toubiaobili)
    RadioButton check_toubiaobili;
    //固定金额
    @Bind(R.id.check_gudingmoney)
    RadioButton check_gudingmoney;

    private String no_yeid;



    private String antian_id = "no";


    private String dingxiang_id = "0";


    public List<JsonBorrowindex.Info.ListContent> borrow_type_list = new ArrayList<>();

    public List<String> list_borrow_type = new ArrayList<>();
    private String borrow_type_id;



    @Bind(R.id.toubiaojiangli)
    EditText toubiaojiangli;


    @Bind(R.id.editText)
    EditText editText;
    //待收money
    @Bind(R.id.edit_money)
    EditText edit_money;


    private boolean flag_jiangli = false;
    private BorrowPop borrowPop;

    @Bind(R.id.img_first)
    ImageView img_first;
    @Bind(R.id.img_second)
    ImageView img_second;
    @Bind(R.id.img_third)
    ImageView img_third;
    @Bind(R.id.img_fourth)
    ImageView img_fourth;

    @Bind(R.id.nolimit_layout)
    LinearLayout nolimit_layout;
    @Bind(R.id.alllimit_layout)
    LinearLayout alllimit_layout;

    @Bind(R.id.montylimit_layout)
    LinearLayout montylimit_layout;

    @Bind(R.id.daylimit_layout)
    LinearLayout daylimit_layout;
    @Bind(R.id.layout_money)
    LinearLayout layout_money;


    String pay;
    Double doubleget_pay;
    int get_pay;




    public void getData() {
        for (int i = 0; i < 10; i++) {
            data.add("i" + i);
        }
    }

    private float popBottom;


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = BoundViewHelper.boundView(this, MyApplication.scaleScreenHelper.loadView((ViewGroup) inflater.inflate(R.layout.fragment_fourth2, null)));
        ButterKnife.bind(this, view);

        initListener();


        layoutLeft = getActivity().getLayoutInflater().inflate(
                R.layout.pop_menulist, null);
        menulistLeft = (ListView) layoutLeft
                .findViewById(R.id.menulist);



        getData();
        getTypeAccessToken();


        radiobuttonlinstener();
        return view;
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        borrowPop = new BorrowPop(getActivity());
    }

    private void initListener() {


        btNext.setOnClickListener(this);
        btNext.setOnClickListener(this);




        //最高投资金额布局
        maxborrow_layout.setOnClickListener(this);
        et_maxinvest.setOnClickListener(this);
//最低投资金额布局
        minborrow_layout.setOnClickListener(this);
        et_mininvest.setOnClickListener(this);
//有效时间




        editText.setOnClickListener(this);
        editText.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                pay = editText.getText().toString().trim();

                if (TextUtils.isEmpty(pay)) {
          /*       LovelyToast.makeText(getContext(), "请输入固定金额分摊比例", 0, LovelyToast
                            .SUCCESS, LovelyToast.SCALE);*/
                } else if (!TextUtils.isEmpty(pay)) {

                    doubleget_pay = Double.valueOf(pay);
                    get_pay = doubleget_pay.intValue();
                    if (pay.contains(".") && (pay.length() - pay.indexOf(".") - 1) > 2) {
                        LovelyToast.makeText(getContext(), "投标比例输入格式不对", 0, LovelyToast
                                .SUCCESS, LovelyToast.SCALE);
                    }

                }


            }
        });


        toubiaojiangli.setOnClickListener(this);
        toubiaojiangli.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                jinebili = toubiaojiangli.getText().toString();


                if (TextUtils.isEmpty(jinebili)) {
                 /*   LovelyToast.makeText(getContext(), "请输入借款总额", 0, LovelyToast
                            .SUCCESS, LovelyToast.SCALE);*/
                } else if (!TextUtils.isEmpty(jinebili)) {

                    double_pay = Double.valueOf(jinebili);
                    int_pay = double_pay.intValue();
                    if (jinebili.contains(".") && (jinebili.length() - jinebili.indexOf(".") - 1) > 2) {
                        LovelyToast.makeText(getContext(), "投标比例输入格式不对", 0, LovelyToast
                                .SUCCESS, LovelyToast.SCALE);
                    }

                }


            }
        });



        nolimit_layout.setOnClickListener(this);
        alllimit_layout.setOnClickListener(this);
        montylimit_layout.setOnClickListener(this);
        daylimit_layout.setOnClickListener(this);


    }

    public void radiobuttonlinstener() {


        if (TextUtils.isEmpty(MyApplication.myPreferences.readUid())) {

            LovelyToast.makeText(getContext(), "请登录之后进行操作", 0, LovelyToast
                    .SUCCESS, LovelyToast.SCALE);
        } else {

            check_toubiaobili.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
                @Override
                public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                    if (isChecked) {
                        no_yeid = "1";

                        check_gudingmoney.setChecked(false);
                    } else {
                        no_yeid = "2";

                    }
                }
            });

            check_gudingmoney.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
                @Override
                public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                    if (isChecked) {
                        no_yeid = "2";

                        check_toubiaobili.setChecked(false);
                    } else {
                        no_yeid = "1";


                    }
                }
            });



        }


    }

    @Override
    public void onStart() {
        super.onStart();

    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.unbind(this);
    }

    @Override
    public void onClick(View v) {
        if (TextUtils.isEmpty(MyApplication.myPreferences.readUid())) {


            LovelyToast.makeText(getContext(), "请登录之后进行操作", 0, LovelyToast
                    .SUCCESS, LovelyToast.SCALE);
        } else {
            switch (v.getId()) {




                       /* nolimit_layout.setOnClickListener(this);
                    alllimit_layout.setOnClickListener(this);
                    montylimit_layout.setOnClickListener(this);
                    daylimit_layout.setOnClickListener(this);*/

                case R.id.montylimit_layout:
                case daylimit:


                    daishou_id = daishou_str.get(2);
                    img_third.setBackground(getResources().getDrawable(R.mipmap.choose_sel));
                    img_first.setBackground(getResources().getDrawable(R.mipmap.choose_no));
                    img_second.setBackground(getResources().getDrawable(R.mipmap.choose_no));
                    img_fourth.setBackground(getResources().getDrawable(R.mipmap.choose_no));
                    layout_money.setVisibility(View.VISIBLE);
                    break;

                case R.id.nolimit_layout:
                case nolimit:
                    daishou_id = daishou_str.get(0);
                    img_first.setBackground(getResources().getDrawable(R.mipmap.choose_sel));
                    img_second.setBackground(getResources().getDrawable(R.mipmap.choose_no));
                    img_third.setBackground(getResources().getDrawable(R.mipmap.choose_no));
                    img_fourth.setBackground(getResources().getDrawable(R.mipmap.choose_no));
                    layout_money.setVisibility(View.GONE);
                    break;

                case R.id.alllimit_layout:
                case tender_award_nosel_rb:
                    daishou_id = daishou_str.get(1);

                    img_second.setBackground(getResources().getDrawable(R.mipmap.choose_sel));
                    img_first.setBackground(getResources().getDrawable(R.mipmap.choose_no));
                    img_third.setBackground(getResources().getDrawable(R.mipmap.choose_no));
                    img_fourth.setBackground(getResources().getDrawable(R.mipmap.choose_no));
                    layout_money.setVisibility(View.VISIBLE);
                    break;

                case all_limit:
                case R.id.daylimit_layout:
                    daishou_id = daishou_str.get(3);
                    img_fourth.setBackground(getResources().getDrawable(R.mipmap.choose_sel));
                    img_first.setBackground(getResources().getDrawable(R.mipmap.choose_no));
                    img_third.setBackground(getResources().getDrawable(R.mipmap.choose_no));
                    img_second.setBackground(getResources().getDrawable(R.mipmap.choose_no));
                    layout_money.setVisibility(View.VISIBLE);
                    break;






                case R.id.et_01:


                    break;

                case R.id.iv_01:


                case R.id.et_05:

                    break;
                case R.id.iv_04:

                case R.id.iv_05:
                case R.id.bt_next:
                    if (MyApplication.myPreferences.readUid().isEmpty()) {
                        LovelyToast.makeText(getContext(), "请登录之后进行操作", 0, LovelyToast
                                .SUCCESS, LovelyToast.SCALE);
                    }  else if (a < 50) {
                        LovelyToast.makeText(getContext(), "您输入的借款总金额不正确", 0, LovelyToast
                                .SUCCESS, LovelyToast.SCALE);

                    } else if (str_allmoney.contains(".") && (str_allmoney.length() - str_allmoney.indexOf(".") - 1) > 2) {
                        LovelyToast.makeText(getContext(), "您输入的借款总金额不正确", 0, LovelyToast
                                .SUCCESS, LovelyToast.SCALE);
                    }   else if (TextUtils.isEmpty(borrow_type_id)) {


                        LovelyToast.makeText(getContext(), "请选择借款类型", 0, LovelyToast
                                .SUCCESS, LovelyToast.SCALE);
                    } else if (TextUtils.isEmpty(borrow_use_id)) {

                        LovelyToast.makeText(getContext(), "请选择借款借款用途", 0, LovelyToast
                                .SUCCESS, LovelyToast.SCALE);

                    } else if (TextUtils.isEmpty(zuigao_id)) {


                        LovelyToast.makeText(getContext(), "请选择最高投资金额", 0, LovelyToast
                                .SUCCESS, LovelyToast.SCALE);
                    } else if (TextUtils.isEmpty(borrow_min_id)) {

                        LovelyToast.makeText(getContext(), "请选择最低投资金额", 0, LovelyToast
                                .SUCCESS, LovelyToast.SCALE);
                    } else if (a > Integer.valueOf(zuigao_id) && Integer.valueOf(zuigao_id) != 0) {

                        LovelyToast.makeText(getContext(), "借款总金额不能高于最高投资金额相同", 0, LovelyToast
                                .SUCCESS, LovelyToast.SCALE);
                    }else if (a==Integer.valueOf(zuigao_id)){
                        LovelyToast.makeText(getContext(), "借款总金额不能等于最高投资金额", 0, LovelyToast
                                .SUCCESS, LovelyToast.SCALE);
                    }

                    else if (Integer.valueOf(borrow_min_id) > a) {
//                        最低投资金额不能大约借款总金额
                        LovelyToast.makeText(getContext(), " 最低投资金额不能大于借款总金额", 0, LovelyToast
                                .SUCCESS, LovelyToast.SCALE);
                    } else if (Integer.valueOf(zuigao_id) < Integer.valueOf(borrow_min_id) && Integer.valueOf(zuigao_id) != 0) {
                        LovelyToast.makeText(getContext(), "最高投资金额不能小于最低投资金额", 0, LovelyToast
                                .SUCCESS, LovelyToast.SCALE);
                    }

                    /* else if (Integer.valueOf(zuigao_id) < Integer.valueOf(borrow_min_id)) {

                        LovelyToast.makeText(getContext(), "最高投资金额不能小于最低投资金额", 0, LovelyToast
                                .SUCCESS, LovelyToast.SCALE);
                    }*/
                    else if (TextUtils.isEmpty(borrow_time_id)) {

                        LovelyToast.makeText(getContext(), "请选择有效时间", 0, LovelyToast
                                .SUCCESS, LovelyToast.SCALE);
                    } else if (TextUtils.isEmpty(type_repyment)) {

                        LovelyToast.makeText(getContext(), "请选择还款方式", 0, LovelyToast
                                .SUCCESS, LovelyToast.SCALE);
                    } else if (TextUtils.isEmpty(daikuanqixian)) {

                        LovelyToast.makeText(getContext(), "请选择贷款期限", 0, LovelyToast
                                .SUCCESS, LovelyToast.SCALE);

                    }    else if (TextUtils.isEmpty(daishou_id)) {

                        LovelyToast.makeText(getContext(), "请选择待收限制", 0, LovelyToast
                                .SUCCESS, LovelyToast.SCALE);

                    } else if (!daishou_id.equals("0") && TextUtils.isEmpty(edit_money.getText().toString().trim())) {

                        LovelyToast.makeText(getContext(), "请填写待收金额", 0, LovelyToast
                                .SUCCESS, LovelyToast.SCALE);

                    } else {


                        Intent intent = new Intent();
//uid
                        intent.putExtra("uid", MyApplication.myPreferences.readUid());
                        //借款类型
                        intent.putExtra("borrow_type", borrow_type_id);
                        //借款金额




                        intent.putExtra("zuigao_id", zuigao_id);
                        intent.putExtra("daishou_id", daishou_id);

                        intent.putExtra("antian_id", antian_id);
                        //借款期限
                        intent.putExtra("daikuanqixian", daikuanqixian);
                        //贷款用途

                        intent.putExtra("borrow_use_id", borrow_use_id);
                        intent.putExtra("borrow_min_id", borrow_min_id);
                        intent.putExtra("zuigao_id", zuigao_id);
                        intent.putExtra("borrow_time_id", borrow_time_id);
                        //还款方式
                        intent.putExtra("type_repyment", type_repyment);

                        intent.putExtra("no_yeid", no_yeid);
//是否定向投标
                        intent.putExtra("dingxiang_id", dingxiang_id);



                        intent.putExtra("edit_money", edit_money.getText().toString().trim());


                        intent.setClass(getActivity(), IoanActivity.class);


                        startActivity(intent);



                        et_maxinvest.setText("");
                        et_mininvest.setText("");

                        check_toubiaobili.setChecked(false);
                        toubiaojiangli.setText("");
                        check_gudingmoney.setChecked(false);

                        editText.setText("");

                    }


                    break;


                case R.id.maxborrow_layout:
                case R.id.et_maxinvest:
                    getpullData();

                    break;

                //最低投资金额
                case R.id.minborrow_layout:
                case R.id.et_mininvest:
                    getminBorrow();
                    break;

//有效时间
                case R.id.timement_layout:

                    break;


                //借款类型
                case R.id.borrow_use_type:
                case borrow_type:



            }
        }

    }

    private void getTypeAccessToken() {
        new JsonAccessToken("index/borrow", new AsyCallBack<JsonAccessToken.Info>() {
            @Override
            public void onSuccess(String toast, int type, JsonAccessToken.Info info) throws Exception {
                if (info != null) {
                    if (!TextUtils.isEmpty(info.access_token)) {
                        onTypeInfo(info.access_token);
                    } else {
                        //  UtilToast.show(getActivity(), "安全验证失败！");
                        LovelyToast.makeText(getContext(), "安全验证失败", 0, LovelyToast
                                .SUCCESS, LovelyToast.SCALE);
                    }

                }

            }

            @Override
            public void onFail(String toast, int type) throws Exception {
                super.onFail(toast, type);
                //  UtilToast.show(getActivity(), "安全验证失败！");
                LovelyToast.makeText(getContext(), "安全验证失败", 0, LovelyToast
                        .SUCCESS, LovelyToast.SCALE);
            }
        }).execute(getActivity(), false);

    }


    private void onTypeInfo(String access_token) {


        new JsonBorrowindex(access_token, new AsyCallBack<JsonBorrowindex.Info>() {
            @Override
            public void onSuccess(String toast, int type, JsonBorrowindex.Info info) throws Exception {

                if (info != null) {
                    borrow_type_list = info.borrow_type;
                    // borrow_type_list.clear();
                    for (int i = 0; i < borrow_type_list.size(); i++) {
                        list_borrow_type.add(borrow_type_list.get(i).name);
                    }


                    borrow_use = info.borrow_use;
                    stringListBorrow_use.clear();
                    for (int i = 0; i < borrow_use.size(); i++) {
                        stringListBorrow_use.add(borrow_use.get(i).name);
                    }
//最高投资  private List<JsonBorrowindex.Info.ListContent> borrow_max = new ArrayList<>();
//                    private List<String> stringListBorrow_max = new ArrayList<>();

                    //最高投资
                    borrow_max = info.borrow_max;
                    stringListBorrow_max.clear();
                    for (int i = 0; i < borrow_max.size(); i++) {
                        stringListBorrow_max.add(borrow_max.get(i).name);
                    }
//最低投资
                    borrow_min = info.borrow_min;
                    borrow_min_list.clear();
                    for (int i = 0; i < borrow_min.size(); i++) {
                        borrow_min_list.add(borrow_min.get(i).name);
                    }

                    //有效时间
                    borrow_time = info.borrow_time;
                    borrow_time_list.clear();
                    for (int i = 0; i < borrow_time.size(); i++) {
                        borrow_time_list.add(borrow_time.get(i).name);
                    }

                    borrow_duration_month = info.borrow_duration_month;
                    myborrow_duration.clear();
                    for (int i = 0; i < borrow_duration_month.size(); i++) {
                        myborrow_duration.add(borrow_duration_month.get(i).name);
                    }


                    retypement = info.repayment_type;
                    //  str_retypement.clear();
                    for (int i = 0; i < retypement.size(); i++) {
                        str_retypement.add(retypement.get(i).name);
                    }


                    borrow_use_day = info.borrow_duration_day;
                    stringListBorrow_use_day.clear();
                    for (int i = 0; i < borrow_use_day.size(); i++) {
                        stringListBorrow_use_day.add(borrow_use_day.get(i).name);
                    }


//是否奖励
                    reward_type = info.reward_type;

                    for (int i = 0; i < reward_type.size(); i++) {
                        reward_type_list.add(reward_type.get(i).id);
                        reward_type_id = reward_type_list.get(i);
                    }
                    check_toubiaobili.setText(reward_type.get(0).name);
                    check_gudingmoney.setText(reward_type.get(1).name);


                    borrow_min = info.borrow_min;
                    borrow_min_list.clear();
                    for (int i = 0; i < borrow_min.size(); i++) {
                        borrow_min_list.add(borrow_min.get(i).name);
                    }


                    daishou = info.daishou;
                    //待收
                    for (int i = 0; i < daishou.size(); i++) {
                        daishou_str.add(daishou.get(i).id);
                    }




                }


            }

            @Override
            public void onFail(String toast, int type) throws Exception {
                //   UtilToast.show(getActivity(), JsonBorrowindex.TOAST);
                LovelyToast.makeText(getContext(), JsonBorrowindex.TOAST, 0, LovelyToast
                        .SUCCESS, LovelyToast.SCALE);
            }

            @Override
            public void onEnd(String toast, int type) throws Exception {

            }

        }).execute(getActivity(), false);

    }


    @Override
    public void onResume() {


        super.onResume();
        if (MyApplication.canClean) {

        } else {
            MyApplication.canClean = false;
        }

    }


    @Override
    public void onHiddenChanged(boolean hidden) {
        super.onHiddenChanged(hidden);
        Log.d("111111111111","22222222222222222");


    }



    public void getminBorrow() {
        //最低投资金额

        if (popLeft != null && popLeft.isShowing()) {
            popLeft.dismiss();
        } else {
        /*    layoutLeft = getActivity().getLayoutInflater().inflate(
                    R.layout.pop_menulist, null);
            menulistLeft = (ListView) layoutLeft
                    .findViewById(R.id.menulist);*/
           // menulistLeft.setAdapter(new ArrayAdapter<String>(getActivity(), R.layout.spinner_list_item, borrow_min_list));

            AnswerQuestionAdapter mAdapter=new AnswerQuestionAdapter(getActivity(),borrow_type_list);
            menulistLeft.setAdapter(mAdapter);

            menulistLeft.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

                   /* private List<JsonBorrowindex.Info.ListContent> borrow_min = new ArrayList<>();
                    private String borrow_min_id;
                    private List<String> borrow_min_list = new ArrayList<>();*/

                    et_mininvest.setText(borrow_min.get(position).name);
                    borrow_min_id = borrow_min.get(position).id;


                    popLeft.dismiss();
                }
            });
            popLeft = new PopupWindow(layoutLeft, minborrow_layout.getWidth(),
                    RelativeLayout.LayoutParams.WRAP_CONTENT);
      /*      ColorDrawable cd = new ColorDrawable(getResources().getColor(R.color.colorWhite));
            popLeft.setBackgroundDrawable(cd);*/
//            ColorDrawable cd = new ColorDrawable(-0000);
            //ColorDrawable cd = new ColorDrawable(0xffff0000);


            popLeft.setAnimationStyle(R.style.PopupAnimation);
            popLeft.update();
            popLeft.setInputMethodMode(PopupWindow.INPUT_METHOD_NEEDED);
            popLeft.setTouchable(true); // 设置popupwindow可点击
            popLeft.setOutsideTouchable(true); // 设置popupwindow外部可点击
            popLeft.setFocusable(true); // 获取焦点

            popLeft.showAsDropDown(minborrow_layout, 0, 0);
            popLeft.setTouchInterceptor(new View.OnTouchListener() {

                @Override
                public boolean onTouch(View v, MotionEvent event) {
                    // 如果点击了popupwindow的外部，popupwindow也会消失
                    if (event.getAction() == MotionEvent.ACTION_OUTSIDE) {
                        popLeft.dismiss();
                        return true;
                    }
                    return false;
                }
            });

        }
    }










    //最高投资金额

    public void getpullData() {
        if (popLeft != null && popLeft.isShowing()) {
            popLeft.dismiss();
        } else {
            layoutLeft = getActivity().getLayoutInflater().inflate(
                    R.layout.pop_menulist, null);
            menulistLeft = (ListView) layoutLeft
                    .findViewById(R.id.menulist);
             AnswerQuestionAdapter myAdapter;
          myAdapter = new AnswerQuestionAdapter(getContext(),borrow_type_list);

            menulistLeft.setAdapter(myAdapter);
            menulistLeft.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//                    tvLeft.setText(list.get(position));
                    Toast.makeText(getContext(), "aaaaaaaaaaaaa", Toast.LENGTH_SHORT).show();
                    // popupWindow.dismiss();
                    popLeft.dismiss();
                }
            });
            popLeft = new PopupWindow(layoutLeft, maxborrow_layout.getWidth(),
                    RelativeLayout.LayoutParams.WRAP_CONTENT);

            ColorDrawable cd = new ColorDrawable(-0000);
            popLeft.setBackgroundDrawable(cd);
            popLeft.setAnimationStyle(R.style.PopupAnimation);
            popLeft.update();
            popLeft.setInputMethodMode(PopupWindow.INPUT_METHOD_NEEDED);
            popLeft.setTouchable(true); // 设置popupwindow可点击
            popLeft.setOutsideTouchable(true); // 设置popupwindow外部可点击
            popLeft.setFocusable(true); // 获取焦点

            // 设置popupwindow的位置（相对tvLeft的位置）
            //  int topBarHeight = rlTopBar.getBottom();
//                        popLeft.showAsDropDown(tvLeft, 0,
//                                (topBarHeight - tvLeft.getHeight()) / 2);
            popLeft.showAsDropDown(maxborrow_layout, 0, 0);
            popLeft.setTouchInterceptor(new View.OnTouchListener() {

                @Override
                public boolean onTouch(View v, MotionEvent event) {
                    // 如果点击了popupwindow的外部，popupwindow也会消失
                    if (event.getAction() == MotionEvent.ACTION_OUTSIDE) {
                        popLeft.dismiss();
                        return true;
                    }
                    return false;
                }
            });

        }
    }


/*    public void getBorrowmax() {
//借款用途

        if (popLeft != null && popLeft.isShowing()) {
            popLeft.dismiss();
        } else {
            *//*layoutLeft = getActivity().getLayoutInflater().inflate(
                    R.layout.pop_menulist, null);
            menulistLeft = (ListView) layoutLeft
                    .findViewById(R.id.menulist);*//*
            menulistLeft.setAdapter(new ArrayAdapter<String>(getActivity(), R.layout.spinner_list_item, data));

            menulistLeft.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

                    Toast.makeText(getContext(), "屌页面", Toast.LENGTH_SHORT).show();
                    *//*zuigao_id = borrow_max.get(position).id;


                    et_maxinvest.setText(stringListBorrow_max.get(position));
                    et_moneymax = stringListBorrow_max.get(position);

                    popLeft.dismiss();*//*
                }
            });
            popLeft = new PopupWindow(layoutLeft, maxborrow_layout.getWidth(),
                    RelativeLayout.LayoutParams.WRAP_CONTENT);
          *//*  ColorDrawable cd = new ColorDrawable(getResources().getColor(R.color.colorWhite));
//
            popLeft.setBackgroundDrawable(cd);*//*
            popLeft.setAnimationStyle(R.style.PopupAnimation);
            popLeft.update();
            popLeft.setInputMethodMode(PopupWindow.INPUT_METHOD_NEEDED);
            popLeft.setTouchable(true); // 设置popupwindow可点击
            popLeft.setOutsideTouchable(true); // 设置popupwindow外部可点击
            popLeft.setFocusable(true); // 获取焦点

            popLeft.showAsDropDown(maxborrow_layout, 0, 0);
            popLeft.setTouchInterceptor(new View.OnTouchListener() {

                @Override
                public boolean onTouch(View v, MotionEvent event) {
                    // 如果点击了popupwindow的外部，popupwindow也会消失
                    if (event.getAction() == MotionEvent.ACTION_OUTSIDE) {
                        popLeft.dismiss();
                        return true;
                    }
                    return false;
                }
            });

        }
    }*/




}
